﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="StudyCenter.aspx.cs" Inherits="ExaminationSys.StudyCenter" MasterPageFile="~/View/Share/Index.Master" %>
<%@ Import Namespace="ExaminationSys.DataAccess.Entity" %>

<asp:Content ID="head" ContentPlaceHolderID="head" runat="server">
 <script src="js/jquery.js" type="text/javascript"></script>
   <link type="text/css" rel="stylesheet" media="all" href="css/others.css" />

   <script type="text/javascript">
       $(function () {
           $("#btnSignOut").click(function () {
               var answer = confirm("是否退出?");
               if (answer) {

                   $.ajax({
                       type: "GET",
                       cache: false,
                       contentType: "application/json",
                       url: "ashx/StudentSignOutHandler.ashx",
                       dataType: 'json',
                       data: null,
                       async: false,
                       success: function (data) {
                           if (data != '200') {
                               alert('操作失败'); return false;
                           }
                           else {
                               var host = window.location.host;
                               window.location.href = "http://" + host + "/Index.aspx";
                           }
                       }
                   });
               }
           });
       });
</script>
 
 </asp:Content>
 <asp:Content ID="headerContent" ContentPlaceHolderID="HeaderHolder" runat="server">
    <div class="h-top">
        <div class="logo fl">
            <img src="images/logo.gif" alt="上海交通大学英语学习中心" /></div>
        <div class="navandsearch fr">
            <ul class="nav">
                  <li><a class="nav-home" href="Index.aspx" title="首页">首页</a></li>
                <li><a class="nav-info" href="Newslist.aspx" title="信息快递">信息快递</a></li>
                <li><a class="nav-help" href="Help.aspx" title="帮助">帮助</a></li>
            </ul>
            <div class="h-search">
                <input id="textKey" class="text" name="" type="text" value="搜索信息" />
                <input id="btnSearch" class="publicbtn btn-search" name="" type="button" value="搜索" />
            </div>
        </div>
        <!--end navandsearch-->
    </div>
    <div class="h-banner">
        <img src="images/pic/pic02.jpg" width="966" height="308" /></div>
</asp:Content>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentHolder" runat="server">

    	<div class="side">
        	<div class="box203">
            	<div class="titles"><img src="images/tit_xx.gif" alt="用户信息"/></div>
            	<div class="conts side-login-on">
                	<p class="tit"><span class="red">欢迎您！</span><span><%=LoginName%></span>同学</p>
                	<ul>
                    	<li><a href="Profile.aspx">个人资料</a></li>
                        <li><a href="ChangePassword.aspx">密码修改</a></li>
                    </ul>
                    
                    <div class="button">                    
                    <a href="StudyCenter.aspx" id="btnStudycenter"><span style="border:1px solid #e3e3e3;color:red;padding:3px;margin:18px">学习中心</span></a>
                    <input id="btnSignOut" class="publicbtn btn-logout" name="" type="button"  value="退出"/></div>	
                </div>
                <div class="box-bbg"></div>
            </div>
            <div class="side-bang">
                <ul class="red">
                    <li class="li_1"><%=DiligentRank %></li>
                    <li class="li_2"><%=ChampionRank%></li>
                </ul>
            </div>
            
            <div class="login-on-info">
            	<h3><span>登录信息</span></h3>
                <p> 您共登陆了 <b><span class="red"><%= LoginCount%></span> 次</b></p>
                <p class="his"> 您的上次登陆时间为：<span class="red"><%=LastLoginTime%></span></p>
            </div>
           
        </div><!--end side-->
        <div class="contents">

        <%
            var pos = 0;
            foreach (var sectionInfo in SectionInfoCollection)
            {
                //if (sectionInfo.SectionTypeID == 1)
                //{
                //    if (!ExistsPaperInfo(sectionInfo.ID)) continue;
                //}
                
                /*begin dl*/
                pos += 1;
                if(pos==1)
                {
                    htmlStrSectionInfo.Append(" <dl class=\"study-cent study-cent-fist\"> ");
                }
                else
                {
                    htmlStrSectionInfo.Append(" <dl class=\"study-cent\"> ");
                }


                htmlStrSectionInfo.Append("<dt>");
                htmlStrSectionInfo.AppendFormat("   <span class=\"subtit\">{0}</span>", sectionInfo.Name);

                if (sectionInfo.SectionTypeID == 1)
                {
                    htmlStrSectionInfo.AppendFormat(
                        "   <span class=\"pic\"><a href=\"StudentCenter.aspx?sectionid={0}\" ><img style='width:184px' src=\"{1}\" alt=\"{2}\"/></a></span>",
                        sectionInfo.ID,
                        string.IsNullOrEmpty(sectionInfo.Img) ? "images/defaultSection.png" : sectionInfo.Img,
                        sectionInfo.Name);
                }
                else if(sectionInfo.SectionTypeID==3)
                {
                    //下载模块
                    htmlStrSectionInfo.AppendFormat(
                         "   <span class=\"pic\"><a href=\"Downlist.aspx\" ><img style='width:184px' src=\"{0}\" alt=\"{1}\"/></a></span>",
                         string.IsNullOrEmpty(sectionInfo.Img) ? "images/defaultSection.png" : sectionInfo.Img,
                         sectionInfo.Name);
                }
                else
                {
                    htmlStrSectionInfo.AppendFormat(
                          "   <span class=\"pic\"><img style='width:184px' src=\"{0}\" alt=\"{1}\"/></span>",
                          string.IsNullOrEmpty(sectionInfo.Img) ? "images/defaultSection.png" : sectionInfo.Img,
                          sectionInfo.Name);

                }
                htmlStrSectionInfo  .Append("</dt>");

                htmlStrSectionInfo.Append("<dd>");

                if (sectionInfo.SectionTypeID == 1)
                {
                    //if (!ExistsPaperInfo(sectionInfo.ID)) //如果没有设置试卷
                    //{
                    //    htmlStrSectionInfo.AppendFormat("<p>此栏目未添加试卷，还没开始，请耐心等待！</p>");
                    //    continue;
                    //}
                    
                    //学习栏目
                    Guid resouceId = Guid.Empty;
                    var paperInfos = GetSectionPaperBySectionId(sectionInfo.ID);
                    var login = GetLoginSection(sectionInfo.ID.ToString());
                    bool hasTest = login != null;
                    if (login == null)
                    {
                        htmlStrSectionInfo.AppendFormat("<p><span>您还没有登录过该栏目<a href=\"StudentCenter.aspx?sectionid={0}\" >[点击进入]</a></span></p>", sectionInfo.ID);
                    }
                    else
                    {
                        htmlStrSectionInfo.AppendFormat("<p>上次登录时间  {0}</p>",
                                                        login.LoginTime.ToString("yyyy-MM-dd HH:mm"));
                        if (StudentTestHistorCollection != null && StudentTestHistorCollection.Count > 0)
                        {
                            
                            //状态为-1时，表示未考试完成，找出最近中断的试卷
                            var latestTest =
                                StudentTestHistorCollection.FindAll(c => c.Status == -1).OrderByDescending(
                                    c => c.TestStartTime).FirstOrDefault();
                            
                            if(latestTest!=null)
                            {
                                resouceId = latestTest.PaperInfoID;
                                var prevTestItem = GetPaperInfo(latestTest.PaperInfoID);
                                if (prevTestItem != null)
                                {
                                    var paper = paperInfos.FindAll(r => r.PaperID == resouceId).FirstOrDefault();
                                    var showName = prevTestItem.Title;
                                    if(paper!=null)
                                    {
                                        showName = paper.TestType == (int) EnumTestType.水平测试 ? "水平测试" : "动机测试";
                                    }
                                    htmlStrSectionInfo.AppendFormat("<p>上一次中断处<a href=\"View/Student/JoinExamination.aspx?paperid={0}&sid={1}&stype=2\">『{2}』</a></p> ", prevTestItem.ID, sectionInfo.ID, showName);
                                }
                            }

                        }

                        //if(!string.IsNullOrEmpty(login.LastResourceID))
                        //{
                        //    if (Guid.TryParse(login.LastResourceID, out resouceId))
                        //    {
                        //        var prevTestItem = GetPaperInfo(resouceId);
                        //        if (prevTestItem != null)
                        //        {
                        //            htmlStrSectionInfo.AppendFormat("<p>上一次中断处<a href=\"考试.aspx?id={0}\">『{1}』</a></p> ",prevTestItem.ID, prevTestItem.Title);
                        //        }
                        //    }
                        //}
                    }

                    #region 构造水平测试及动机测试
                    if (paperInfos != null && paperInfos.Count > 0)
                    {
                        if (resouceId != Guid.Empty)
                        {
                            //上次中断处的，不能继续显示(已在上面特殊显示了)
                            paperInfos = paperInfos.FindAll(r => r.PaperID != resouceId);
                        }

                        if (StudentTestHistorCollection != null && StudentTestHistorCollection.Count > 0)
                        {
                            var tmp = new List<ExaminationSys.DataAccess.Entity.SectionPaper>();

                            foreach (var p in paperInfos)
                            {
                                if (StudentTestHistorCollection.Any(c => c.PaperInfoID.Equals(p.PaperID) && c.Status == 1))
                                    continue;
                                tmp.Add(p);
                            }
                            paperInfos = tmp;
                        }
                        /*
                            动机测试=1,
                            水平测试=2
                         */
                        var proficiencyItems =
                            paperInfos.FindAll(
                                p => p.TestType == (int)EnumTestType.水平测试);
                        if (proficiencyItems.Count > 0)
                        {
                            foreach (var item in proficiencyItems)
                            {
                                //<p><span>您还没有完成该栏目的『水平测试』</span> <span><a class="ico" href="#">点击进行测试</a></span></p> 
                                htmlStrSectionInfo.AppendFormat(
                                    "<p><span>您还没有完成该栏目的『水平测试』</span> <span><a class=\"ico\" href=\"View/Student/JoinExamination.aspx?paperid={0}&sid={1}&stype=2\">点击进行测试</a></span></p>",
                                    item.PaperID, sectionInfo.ID);
                            }
                        }

                        var motivationItems =
                            paperInfos.FindAll(
                                p => p.TestType == (int)EnumTestType.动机测试);
                        if (motivationItems.Count > 0)
                        {
                            foreach (var item in motivationItems)
                            {
                                htmlStrSectionInfo.AppendFormat(
                                    "<p><span>您还没有完成该栏目的『动机测试』</span> <span><a class=\"ico\" href=\"View/Student/JoinExamination.aspx?paperid={0}&sid={1}&stype=2\">点击进行测试</a></span></p>",
                                    item.PaperID, sectionInfo.ID);
                            }
                        }



                        htmlStrSectionInfo.AppendFormat(
                            "<div class=\"button\"><a href=\"Testhistory.aspx?sid={0}\"><img src=\"images/btn-cs.gif\" alt=\"测试历史\"/></a></div>", sectionInfo.ID);

                    }

                    #endregion
                }
                else if (sectionInfo.SectionTypeID==2)
                {
                    //外链接

                    var links = GetSectionLinkBySectionId(sectionInfo.ID.ToString());

                    foreach (var sectionlink in links)
                    {
                        htmlStrSectionInfo.AppendFormat("<p><a href=\"{0}\" target='_blank'>{1}</a></p> ", sectionlink.LinkUrl, sectionInfo.Name);
                    }

                }
                else if (sectionInfo.SectionTypeID == 3)
                {
                    //下载栏目
                    var downloads = GetSectionDownLoadListBySectionId(sectionInfo.ID.ToString());
                    downloads.Sort((x, y) => x.OrderIndex.CompareTo(y.OrderIndex));
                    foreach (var sectiondownload in downloads)
                    {
                        htmlStrSectionInfo.AppendFormat("<p><a href=\"download.aspx?id={0}\" target='_blank'>{1}</a></p> ", sectiondownload.ID, sectiondownload.Title);
                    } 
                }
                else if (sectionInfo.SectionTypeID == 4)
                {
                    //信息栏目
                    var infos = GetSectionInformationListBySectionId(sectionInfo.ID.ToString());
                    foreach (var sectionlink in infos)
                    {
                        htmlStrSectionInfo.AppendFormat("<p><a href=\"#\" target='_blank'>{0}</a></p> ", sectionlink.Title);
                    }
                }
                htmlStrSectionInfo.Append("</dd>");

                htmlStrSectionInfo.Append("</dl>");
                /*end dl*/

            } %>

             <%=htmlStrSectionInfo.ToString()%>

        <%--    <dl class="study-cent study-cent-fist"> 
            	<dt>
                	<span class="subtit">听力</span>  
                	<span class="pic"><img src="images/x-01.gif" alt="听力"/></span>
                </dt>
                <dd>
                	<p><span>您还没有登录过该栏目</span></p>
                	<p><span>您还没有完成该栏目的『水平测试』</span> <span><a class="ico" href="#">点击进行测试</a></span></p> 
                	<p><span>您还没有完成该栏目的『动机测试』</span> <span><a class="ico" href="#">点击进行测试</a></span></p>
                    <div class="button"><a href="#"><img src="images/btn-cs.gif" alt="测试历史"/></a></div>
                </dd>
            </dl>
            <dl class="study-cent"> 
                <dt>
                	<span class="subtit">阅读</span>
                	<span class="pic"><img src="images/x-02.gif" alt="阅读"/></span>
                </dt>
                <dd>
                	<p>上次登录时间  2012-01-01  18：30</p>
                	<p>上一次中断处『单元一自测』</p> 
                	
                    <div class="button"><a href="#"><img src="images/btn-cs.gif" alt="测试历史"/></a></div>
                </dd>
            </dl>
            <dl class="study-cent"> 
                <dt>
                	<span class="subtit">汉译英</span>
                	<span class="pic"><img src="images/x-03.gif" alt="汉译英"/></span>
                </dt>
                <dd>
                <%
                    htmlStr.Clear();
                    foreach (var sectionlink in SectionInfoSearchEntityCollection)
                    {
                        htmlStr.AppendFormat("<p><a href=\"{0}\" target='_blank'>{1}</a></p> ",sectionlink.LinkUrl,sectionlink.SectionName);
                    } %>
                	 <%=htmlStr.ToString() %>
                 
                </dd>
            </dl>
            
            <dl class="study-cent"> 
                <dt>
                	<span class="subtit">下载</span>
                	<span class="pic"><img src="images/x-03.gif" alt="下载"/></span>
                </dt>
                <dd>
                <% htmlStrDownLoad.Clear();
                    foreach (var sectiondownload in SectionDownloadCollection)
                    {
                        htmlStrDownLoad.AppendFormat("<p><a href=\"download.aspx?id={0}\" target='_blank'>{1}</a></p> ", sectiondownload.ID, sectiondownload.Title);
                    } %>
                	 <%=htmlStrDownLoad.ToString()%>
                 
                </dd>
            </dl>--%>
        </div><!--end contents-->
</asp:Content>